home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / imageWindowPanel.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  24.0 KB  |  1,048 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // $RCSfile: imageWindowPanel.mel $
  19. //
  20. // $Source: /vobs/aw/Maya/src/ImageUI/ImageWindow/imageWindowPanel.mel $
  21. //
  22. // $Author: jgross $
  23. // $Revision: /main/2 $
  24. // $Date: 2000/04/07 15:22:53 $
  25. //
  26. // Script:    imageWindowPanel.mel
  27. //
  28. //*AUTOMATIC: yes
  29. //
  30. //
  31. // SYNOPSIS
  32. //
  33. //        Creates a panel that contains the imaging window.
  34. //        This file also contains a bunch of helper procedures related to the
  35. //        imaging window.
  36. //
  37. // AUTHOR Jeando Lauwereins
  38.  
  39.  
  40. //----------------------------------------------------------------------------//
  41.  
  42.  
  43. global proc imageWindowPanel(string $panelName) 
  44. //
  45. //  Description:
  46. //        This proc defines the image window panel type and instantiates
  47. //        one.
  48. //
  49. {
  50.     global string $gMainPane;
  51.  
  52.     //  define the type of panel
  53.     //
  54.     if (!`scriptedPanelType -exists imageWindowPanel`) {
  55.         scriptedPanelType
  56.             -unique true
  57.             -createCallback "createImageWindowPanel" 
  58.             -addCallback "addImageWindowPanel" 
  59.             -removeCallback "removeImageWindowPanel" 
  60.             imageWindowPanel;
  61.  
  62.         //
  63.         //  create an instance of the image window panel
  64.         //
  65.         setParent $gMainPane;
  66.         scriptedPanel -unParent -type "imageWindowPanel" $panelName;
  67.     }
  68. }
  69.  
  70. //----------------------------------------------------------------------------//
  71.  
  72. //
  73. // Description:
  74. //        Sets all the option var specific to the image view.
  75. //    - imageViewTestResolution: 0 => panel resolution.
  76. //                                1 => image globals.
  77. //                                2 => 50% image globals.
  78. //                                3 => 25% image globals.
  79. //                                4 => 10% image globals.
  80. //    - imageViewAutoResize: boolean
  81. //    - imageViewAutoImageRegion: boolean.
  82. //
  83. global proc setImageOptionVars()
  84. {
  85.     if( !`optionVar -exists imageViewTestResolution` )
  86.     {
  87.         optionVar -intValue imageViewTestResolution 1;
  88.     }
  89.     if( !`optionVar -exists imageViewAutoResize` )
  90.     {
  91.         optionVar -intValue imageViewAutoResize 1;
  92.     }
  93.     if( !`optionVar -exists imageViewAutoImageRegion` )
  94.     {
  95.         optionVar -intValue imageViewAutoImageRegion 0;
  96.     }
  97. }
  98.  
  99. global proc switchAutoImageRegionVar()
  100. {
  101.     if( `optionVar -exists imageViewAutoImageRegion` )
  102.     {
  103.         if( `optionVar -query imageViewAutoImageRegion` != 0 )
  104.         {
  105.             optionVar -intValue imageViewAutoImageRegion 0;
  106.         }
  107.         else
  108.         {
  109.             optionVar -intValue imageViewAutoImageRegion 1;
  110.         }
  111.     }
  112.     else
  113.     {
  114.         optionVar -intValue imageViewAutoImageRegion 0;
  115.     }
  116. }
  117.  
  118. proc switchImageAutoResizeVar( string $editor )
  119. {
  120.     if( `optionVar -exists imageViewAutoResize` )
  121.     {
  122.         if( `optionVar -query imageViewAutoResize` != 0 )
  123.         {
  124.             optionVar -intValue imageViewAutoResize 0;
  125.         }
  126.         else
  127.         {
  128.             optionVar -intValue imageViewAutoResize 1;
  129.         }
  130.     }
  131.     else
  132.     {
  133.         optionVar -intValue imageViewAutoResize 1;
  134.     }
  135.  
  136.     $var = `optionVar -q imageViewAutoResize`;
  137.  
  138.     imageWindowEditor -e -ar $var $editor;
  139. }
  140.  
  141. global proc setImageTestResolutionVar( int $choice )
  142. {
  143.     if( `optionVar -exists imageViewTestResolution` &&
  144.         $choice >= 0 && $choice <= 4 )
  145.     {
  146.         optionVar -intValue imageViewTestResolution $choice;
  147.     }
  148.     else
  149.     {
  150.         //
  151.         //    Default is panel resolution.
  152.         //
  153.         optionVar -intValue imageViewTestResolution 1;
  154.     }
  155. }
  156.  
  157. //----------------------------------------------------------------------------//
  158. // Callbacks for the panel
  159. //----------------------------------------------------------------------------//
  160.  
  161. global proc createImageWindowPanel(string $whichPanel)
  162. {
  163.     imageWindowEditor  -unParent  $whichPanel ;
  164.  
  165.     //
  166.     //    Set the options variables.
  167.     //
  168.     setImageOptionVars;
  169. }
  170.  
  171. global proc addImageWindowPanel(string $whichPanel)
  172. {        
  173.     //
  174.     //  Build Menubar.
  175.     //
  176.     imageWindowCreateMenubar($whichPanel, "imageWindowEditor");
  177.  
  178.     //
  179.     //    Create the image view.
  180.     //
  181.     iiWindowEditor( $whichPanel , "imageWindowEditor",
  182.                                   "imageWindowCreatePopup",
  183.                                   "updateImageWindow");
  184.  
  185.     //
  186.     //    Tells the imageWindowEditor what the imageViewAutoResize value
  187.     //    is.
  188.     //
  189.     $var = `optionVar -q imageViewAutoResize`;
  190.     imageWindowEditor -e -ar $var $whichPanel;
  191. }
  192.  
  193. global proc removeImageWindowPanel(string $whichPanel)
  194. {
  195.     imageWindowEditor -e -unParent $whichPanel ;
  196. }
  197.  
  198. global proc updateImageWindow(int $reason)
  199. {;}
  200.  
  201. //----------------------------------------------------------------------------//
  202. //    Main image view menu.
  203. //----------------------------------------------------------------------------//
  204.  
  205. //
  206. //    Description:
  207. //        Image view specific items.
  208. //
  209. global proc imageWindowCreateMenubar(string $editor, string $editorCmd)
  210. {
  211.     menu -l "Image" 
  212.         -to 1
  213.         -postMenuCommandOnce true
  214.         -familyImage "menuIconImage.xpm";
  215.  
  216.     //
  217.     //    Redo last image tries to image with the last camera used.
  218.     //
  219.     menuItem -l "Redo Previous Image" -c "redoLastImage(0)"
  220.              ($editor + "redoLastImageItem");
  221.  
  222.     menuItem -l "Image Region" -c "redoLastImage(1)"
  223.              ($editor + "imageRegionItem");
  224.  
  225.     //
  226.     //    Dynamic image menu, it contains the list of cameras to image
  227.     //    from.
  228.     //
  229.     string    $subName = `menuItem -subMenu true -l "Image"`;
  230.     menuItem -e 
  231.              -pmc ("imageWindowMakeCameraAction "+$subName+" "+$editor+" image")
  232.              $subName;
  233.     setParent -m ..;
  234.  
  235.     //
  236.     //    Dynamic snapshot image menu, it contains the list of visible
  237.     //    camera panels to image from.
  238.     //
  239.     $subName = `menuItem -subMenu true -l "Snapshot"`;
  240.     menuItem -e
  241.              -pmc ("imageWindowMakeCameraAction "+$subName+" "+$editor+" snapshot")
  242.              $subName;
  243.     setParent -m ..;
  244.  
  245.     menuItem -divider true;
  246.  
  247.     //
  248.     //    Show the image globals.
  249.     //
  250.     menuItem -l "Image Globals..." -c "showImageGlobals"
  251.         ($editor+"renderGlobalsItem");
  252.     setParent -m ..;
  253.  
  254.     //
  255.     //    Make the dynamic 'test settings' sub menu.
  256.     //
  257.     $subName = `menu -l "Settings"
  258.             -familyImage "menuIconImageSettings.xpm"`;
  259.      imageWindowMakeTestSettings $subName $editor;
  260.     setParent -m ..;
  261.  
  262.     //
  263.     //    Make the View sub menu.
  264.     //
  265.     $subName = `menu -l "View"
  266.                      -to 1
  267.                      -familyImage "menuIconView.xpm"
  268.                      ($editor+"ViewMenu")`;
  269.     setParent -m $subName;
  270.  
  271.     menuItem -l "Frame Image"
  272.              -c ($editorCmd+" -e -frameImage "+$editor)
  273.              ($editor+"frameImageItem");
  274.     menuItem -l "Frame Region"
  275.              -c ($editorCmd+" -e -frameRegion "+$editor)
  276.              ($editor+"frameRegionItem");
  277.     menuItem -l "Real Size"
  278.              -c ($editorCmd+" -e -realSize "+$editor)
  279.              ($editor+"realSizeItem");
  280.  
  281.     setParent -m ..;
  282.  
  283.     //
  284.     //    Create the common tools of the menuBar.
  285.     //
  286.     iiWindowEditorMenuBar( $editor, $editorCmd );
  287. }
  288.  
  289. //
  290. //    Description:
  291. //        Image view specific items.
  292. //
  293. global proc imageWindowCreatePopup(string $editor, string $editorCmd)
  294. {
  295.     //
  296.     //    Redo last image tries to image with the last camera used.
  297.     //
  298.     menuItem -l "Redo Previous Image" -c "redoLastImage(0)"
  299.              ($editor + "redoLastImageItem");
  300.  
  301.     menuItem -l "Image Region" -c "redoLastImage(1)"
  302.              ($editor + "imageRegionItem");
  303.  
  304.     //
  305.     //    Dynamic image menu, it contains the list of cameras to image
  306.     //    from.
  307.     //
  308.     string    $subName = `menuItem -subMenu true -l "Image"`;
  309.     menuItem -e 
  310.              -pmc ("imageWindowMakeCameraAction "+$subName+" "+$editor+" image")
  311.              $subName;
  312.     setParent -m ..;
  313.  
  314.     //
  315.     //    Dynamic snapshot image menu, it contains the list of visible
  316.     //    camera panels to image from.
  317.     //
  318.     $subName = `menuItem -subMenu true -l "Snapshot"`;
  319.     menuItem -e
  320.              -pmc ("imageWindowMakeCameraAction "+$subName+" "+$editor+" snapshot")
  321.              $subName;
  322.     setParent -m ..;
  323.  
  324.     menuItem -divider true;
  325.  
  326.     //
  327.     //    Make the dynamic 'test settings' sub menu.
  328.     //
  329.     $subName = `menuItem -subMenu true -l "Image View Settings"`;
  330.     menuItem -e
  331.              -pmc ("imageWindowMakeTestSettings " + $subName + " " + $editor)
  332.              $subName;
  333.     setParent -m ..;
  334.  
  335.     //
  336.     //    Show the image globals.
  337.     //
  338.     menuItem -l "Image Globals..." -c "showImageGlobals"
  339.              ($editor+"renderGlobalsItem");
  340.  
  341.     menuItem -divider true;
  342.  
  343.     //
  344.     //    Make the View sub menu.
  345.     //
  346.     $subName = `menuItem -l "View" -sm 1 -to 1 ($editor+"ViewMenu")`;
  347.     setParent -m $subName;
  348.  
  349.     menuItem -l "Frame Image"
  350.              -c ($editorCmd+" -e -frameImage "+$editor)
  351.              ($editor+"frameImageItem");
  352.     menuItem -l "Frame Region"
  353.              -c ($editorCmd+" -e -frameRegion "+$editor)
  354.              ($editor+"frameRegionItem");
  355.     menuItem -l "Real Size"
  356.              -c ($editorCmd+" -e -realSize "+$editor)
  357.              ($editor+"realSizeItem");
  358.  
  359.     setParent -m ..;
  360. }
  361.  
  362. //----------------------------------------------------------------------------//
  363. //                            SUB MENUS PROCEDURES
  364. //----------------------------------------------------------------------------//
  365.  
  366. //
  367. // Description:
  368. //        This procedure is called by TimageWindowSelectCtx.cc that defines
  369. //    a region. It checks if a region can be imageed.
  370. //
  371. global proc imageWindowCheckAndImageRegion
  372.  ( float    $top,
  373.    float    $left,
  374.    float    $bottom,
  375.    float    $right )
  376. {
  377.     //
  378.     //    If there's no current camera (first image), do what has to be
  379.     //    done...
  380.     //
  381.     string    $imagePanel = `getImageWindowPanel`;
  382.     int        $snaped = 0;
  383.  
  384.     //
  385.     //    Otherwise, set the region and image if the imageViewAutoImageRegion
  386.     //    is set to true.
  387.     //
  388.     if( $snaped )
  389.     {
  390.         imageWindowEditor -e -mq $top $left $bottom $right $imagePanel;
  391.  
  392.         if( `optionVar -exists imageViewAutoImageRegion` &&
  393.             `optionVar -query imageViewAutoImageRegion` != 0 )
  394.             redoLastImage(1);
  395.     }
  396. }
  397.  
  398. //
  399. // Description:
  400. //
  401. //
  402. global proc imageWindowMakeResolutionItem
  403.  ( string $subMenuName,
  404.    string $panelName )
  405. {
  406.     popupMenu -e -deleteAllItems $subMenuName;
  407.     setParent -m $subMenuName;
  408.  
  409.     //
  410.     //    Use panel resolution item.
  411.     //
  412.     int $testRes    = `optionVar -q imageViewTestResolution`;
  413.     int    $panelBool    = ( $testRes == 0 );
  414.     int $fullBool    = ( $testRes == 1 );
  415.     int $halfBool    = ( $testRes == 2 );
  416.     int $quaterBool    = ( $testRes == 3 );
  417.     int $tenthBool    = ( $testRes == 4 );
  418.     int $res[]        = `getGlobalsResolution`;
  419.  
  420.     menuItem -l "Camera Panel"
  421.              -cb $panelBool
  422.              -c "setImageTestResolutionVar(0)"
  423.              ($panelName + "panelResolutionItem");
  424.  
  425.     menuItem -l ("Image Globals (" + $res[0] + "x" + $res[1] + ")")
  426.              -cb $fullBool
  427.              -c "setImageTestResolutionVar(1)"
  428.              ($panelName + "fullResolutionItem");
  429.  
  430.     $x = $res[0] / 2;
  431.     $y = $res[1] / 2;
  432.     menuItem -l ("50% Globals (" + $x + "x" + $y + ")")
  433.              -cb $halfBool
  434.              -c "setImageTestResolutionVar(2)"
  435.              ($panelName + "halfResolutionItem");
  436.  
  437.  
  438.     $x = $res[0] / 4;
  439.     $y = $res[1] / 4;
  440.     menuItem -l ("25% Globals (" + $x + "x" + $y + ")")
  441.              -cb $quaterBool
  442.              -c "setImageTestResolutionVar(3)"
  443.              ($panelName + "quaterResolutionItem");
  444.  
  445.     $x = $res[0] / 10;
  446.     $y = $res[1] / 10;
  447.     menuItem -l ("10% Globals (" + $x + "x" + $y + ")")
  448.              -cb $tenthBool
  449.              -c "setImageTestResolutionVar(4)"
  450.              ($panelName + "tenthResolutionItem");
  451. }
  452.  
  453. //
  454. // Description:
  455. //
  456. //
  457. global proc imageWindowMakeTestSettings
  458.  ( string $subMenuName,
  459.    string $panelName )
  460. {
  461.     popupMenu -e -deleteAllItems $subMenuName;
  462.     setParent -m $subMenuName;
  463.  
  464.     //
  465.     //    Resolution used for tests.
  466.     //
  467.     $subName = `menuItem -subMenu true -l "Resolution"`;
  468.     menuItem -e
  469.              -pmc ("imageWindowMakeResolutionItem " + $subName + " " + $panelName)
  470.              $subName;
  471.     setParent -m ..;
  472.  
  473.     $var = `optionVar -q imageViewAutoResize`;
  474.     menuItem -l "Auto Resize"
  475.              -cb $var
  476.              -c ("switchImageAutoResizeVar " + $panelName)
  477.              ($panelName + "autoResizeItem");
  478.  
  479.     $var = `optionVar -q imageViewAutoImageRegion`;
  480.     menuItem -l "Auto Image Region"
  481.              -cb $var
  482.              -c "switchAutoImageRegionVar"
  483.              ($panelName + "autoImageRegionItem");
  484.  
  485.     string    $camera = `getCurrentCamera`;
  486.     string    $panel = `getCameraPanel( $camera )`;
  487.     int        $res[] = `getTestResolution( $panel )`;
  488.  
  489.     menuItem -l "Show Region"
  490.              -c ("imageWindowEditor -e -showRegion " +
  491.                  $res[0] + " " + $res[1] + " " + $panelName)
  492.              ($panelName + "showRegionItem");
  493. }
  494.  
  495. //
  496. // Description:
  497. //        Take a snapshot by creating a temporary model editor whithin the
  498. //    image view window.
  499. //
  500. global proc imageWindowTakeSnapshot
  501.  ( int        $resX,
  502.    int        $resY,
  503.    string    $camera )
  504. {
  505.     //
  506.     //    Raise the image view in case it's partially covered.
  507.     //
  508.     raiseImageViewWindow;
  509.  
  510.     string    $prevParent = `setParent -q`;
  511.     string    $mainForm = `getImageWindowPanelFormLayout`;
  512.  
  513.     setParent $mainForm;
  514.  
  515.     int        $formX = `formLayout -q -w $mainForm`;
  516.     int        $formY = `formLayout -q -h $mainForm`;
  517.     float    $snapX = $resX;
  518.     float    $snapY = $resY;
  519.  
  520.     //
  521.     //    TODO: Not very clean, to be improved.
  522.     //
  523.     while( $snapX > $formX )
  524.     {
  525.         $snapX *= 0.8;
  526.         $snapY *= 0.8;
  527.     }
  528.  
  529.     while( $snapY > $formY )
  530.     {
  531.         $snapX *= 0.8;
  532.         $snapY *= 0.8;
  533.     }
  534.  
  535.     int    $right = ($formX - $snapX);
  536.     int    $bottom = ($formY - $snapY);
  537.  
  538.     //
  539.     //    Create the model editor at the right size and take a snapshot.
  540.     //
  541.     modelEditor imageWindowTMPModelEditor;
  542.  
  543.     formLayout -e -af imageWindowTMPModelEditor left 0 $mainForm;
  544.     formLayout -e -af imageWindowTMPModelEditor right $right $mainForm;
  545.     formLayout -e -af imageWindowTMPModelEditor top 0 $mainForm;
  546.     formLayout -e -af imageWindowTMPModelEditor bottom $bottom $mainForm;
  547.  
  548.     //
  549.     //    Unset camera gates and reset overscan to 1.
  550.     //
  551.     int        $dfg = `camera -q -displayFilmGate $camera`;
  552.     int        $dr = `camera -q -displayResolution $camera`;
  553.     float    $os = `camera -q -overscan $camera`;
  554.  
  555.     camera -e -displayFilmGate off -displayResolution off -overscan 1.0 $camera;
  556.  
  557.     //
  558.     //    Set the right camera to the model editor.
  559.     //
  560.     modelEditor -e -cam $camera imageWindowTMPModelEditor;
  561.  
  562.     //
  563.     //    Ask the image window editor to take the snapshot of the given
  564.     //    modelEditor at the given resolution.
  565.     //
  566.     string    $imagePanel = `getImageWindowPanel`;
  567.  
  568.     // GG: need to make sure tmp window is on top. Otherwise, we keep
  569.     // capturing the imageview.
  570.     imageWindowEditor -e -unParent $imagePanel;
  571.     imageWindowEditor -e -snp imageWindowTMPModelEditor $resX $resY $imagePanel;
  572.     imageWindowEditor -e -parent imageViewWindowPanelLayout_mainForm $imagePanel;
  573.  
  574.     setParent $mainForm;
  575.     deleteUI -ed imageWindowTMPModelEditor;
  576.  
  577.     //
  578.     //    Restore camera settings.
  579.     //
  580.     camera -e -displayFilmGate $dfg -displayResolution $dr -overscan $os $camera;
  581.  
  582.     //
  583.     //    Restore parent state.
  584.     //
  585.     setParent $prevParent;
  586. }
  587.  
  588. //
  589. // Description:
  590. //        Generic procedure to create menus with commands taking cameras
  591. //    into account.
  592. //
  593. global proc imageWindowMakeCameraAction
  594.  ( string    $subMenuName,
  595.    string    $panelName,
  596.    string    $commandeName )
  597. {
  598.     popupMenu -e -deleteAllItems $subMenuName;
  599.     setParent -m $subMenuName;
  600.  
  601.     //
  602.     //    Get the current model panel and then get the image view resolution.
  603.     //
  604.     string    $camera = `getCurrentCamera`;
  605.     string    $currentPanel = `getCameraPanel( $camera )`;
  606.     int        $res[];
  607.  
  608.     $res = `getTestResolution( $currentPanel )`;
  609.  
  610.     //
  611.     //    Build the command.
  612.     //
  613.     string    $command;
  614.  
  615.     if( $commandeName == "image" )
  616.         $command = ($commandeName+" -x "+$res[0]+" -y "+$res[1]+" ");
  617.     else if( $commandeName == "snapshot" )
  618.         $command = ("imageWindowTakeSnapshot "+$res[0]+" "+$res[1]+" ");
  619.  
  620.     //
  621.     //    Build items.
  622.     //
  623.     if( size($currentPanel) != 0 )
  624.     {
  625.         menuItem -l ("Current ("+$camera+")") -c ($command+$camera);
  626.         menuItem -divider true ;
  627.     }
  628.  
  629.     int        $testRes = `optionVar -query imageViewTestResolution`;
  630.  
  631.     //
  632.     //    List all perspective cameras
  633.     //
  634.     string    $persps[] = `listCameras -perspective`;
  635.  
  636.     //
  637.     //    Then we have to use panel resolutions....
  638.     //
  639.     if( $testRes == 0 )
  640.     {
  641.         string    $panel;
  642.  
  643.         for( $i in $persps )
  644.         {
  645.             $panel = `getCameraPanel( $i )`;
  646.             $res = `getTestResolution( $panel )`;
  647.             if( $commandeName == "image" )
  648.                 $command = ($commandeName+" -x "+$res[0]+" -y "+$res[1]+" ");
  649.             else if( $commandeName == "snapshot" )
  650.                 $command = ("imageWindowTakeSnapshot "+$res[0]+" "+$res[1]+" ");
  651.             menuItem -l $i -c ($command+$i);
  652.         }
  653.     }
  654.     else
  655.     {
  656.         for( $i in $persps )
  657.             menuItem -l $i -c ($command+$i);
  658.     }
  659.  
  660.     menuItem -divider true;
  661.  
  662.     //
  663.     //    List all orthographic cameras
  664.     //
  665.     string    $orthos[] = `listCameras -orthographic`;
  666.  
  667.     //
  668.     //    Then we have to use panel resolutions....
  669.     //
  670.     if( $testRes == 0 )
  671.     {
  672.         string    $panel;
  673.  
  674.         for( $i in $orthos )
  675.         {
  676.             $panel = `getCameraPanel( $i )`;
  677.             $res = `getTestResolution( $panel )`;
  678.             if( $commandeName == "image" )
  679.                 $command = ($commandeName+" -x "+$res[0]+" -y "+$res[1]+" ");
  680.             else if( $commandeName == "snapshot" )
  681.                 $command = ("imageWindowTakeSnapshot "+$res[0]+" "+$res[1]+" ");
  682.             menuItem -l $i -c ($command+$i);
  683.         }
  684.     }
  685.     else
  686.     {
  687.         for( $i in $orthos )
  688.             menuItem -l $i -c ($command+$i);
  689.     }
  690. }
  691.  
  692. //
  693. // Description:
  694. //
  695. //
  696. global proc showImageGlobals()
  697. {
  698.     string $globals[] = `ls -renderGlobals`;
  699.     showEditor $globals[0];
  700. }
  701.  
  702. //----------------------------------------------------------------------------//
  703. //                            HELPER PROCEDURES
  704. //----------------------------------------------------------------------------//
  705.  
  706. //
  707. //    This procedure tears (if needed) the imageView panel off
  708. //    and sets the size of the current modelView.
  709. //    When this is done, a image is launch with the size
  710. //    of the imageView panel
  711. //
  712. global proc launchImageOutside()
  713. {
  714.     //
  715.     // get the current 3d panel
  716.     //
  717.     string $currentPanel = `getPanel -wf`;
  718.  
  719.     //
  720.     //    Checks whether the current panel is a model panel...
  721.     //
  722.     if( `getPanel -to $currentPanel` != "modelPanel" )
  723.     {
  724.         confirmDialog -m "Please select the view you want to image" -b "OK" -db "OK";
  725.         return;
  726.     }
  727.  
  728.     //
  729.     // Get the image window panel.
  730.     //
  731.     string $imagePanel = `getImageWindowPanel`;
  732.  
  733.     //
  734.     // If not tore off, do It !
  735.     //
  736.     if( !`scriptedPanel -q -tearOff $imagePanel` )
  737.     {
  738.         scriptedPanel -e -tearOff $imagePanel;
  739.     }
  740.  
  741.     //
  742.     //    Now gets the right resolution.
  743.     //
  744.     int        $res[] = `getTestResolution( $currentPanel )`;
  745.  
  746.     //
  747.     //    If the image view is too small, resize it.
  748.     //
  749.     string    $imageWindowControl = `scriptedPanel -q -control $imagePanel`;
  750.     string    $imageWindow;
  751.     string    $buffer[];
  752.  
  753.     tokenize( $imageWindowControl, "|", $buffer );
  754.     $imageWindow = $buffer[0];
  755.  
  756.     int        $width = `control -q -w $imageWindowControl`;
  757.     int        $height = `control -q -h $imageWindowControl`;
  758.  
  759.     $width -= 40;
  760.     $height -= 60;
  761.  
  762.     if( $width < $res[0] || $height < $res[1] )
  763.     {
  764.         $width = $res[0] + 40;
  765.         $height = $res[1] + 60;
  766.         window -e -w $width -h $height -retain $imageWindow;
  767.     }
  768.  
  769.     //
  770.     //    Image the current camera panel at the test resolution...
  771.     //
  772.     showWindow $imageWindow;
  773.     image -x $res[0] -y $res[1];
  774. }
  775.  
  776. //----------------------------------------------------------------------------//
  777. //
  778. //    Redo last image.
  779. //
  780. global proc redoLastImage( int $forceRegion )
  781. {
  782.     //
  783.     //    Get the current camera of the image window panel.
  784.     //
  785.     string    $camera = `getCurrentCamera`;
  786.     string    $panel = `getCameraPanel( $camera )`;
  787.     int        $res[] = `getTestResolution( $panel )`;
  788.     string    $globals[] = `ls -renderGlobals`;
  789.  
  790.     //
  791.     //    Check whether we have to take the region into account.
  792.     //
  793.     if( $forceRegion )
  794.     {
  795.         if( size($globals[0]) > 0 )
  796.         {
  797.             $forceRegion = 1;
  798.             setAttr ($globals[0] + ".urr") true;
  799.  
  800.             //
  801.             //    Show the region.
  802.             //
  803.             $imagePanel = `getImageWindowPanel`;
  804.             imageWindowEditor -e -showRegion $res[0] $res[1] $imagePanel;
  805.         }
  806.         else
  807.         {
  808.             $forceRegion = 0;
  809.         }
  810.     }
  811.     //
  812.     //    Force the urr flag to be set to false.
  813.     //
  814.     else if( size($globals[0]) > 0 )
  815.         setAttr ($globals[0] + ".urr") false;
  816.  
  817.     //
  818.     //    GO...
  819.     //
  820.     image -x $res[0] -y $res[1] $camera;
  821.  
  822.     //
  823.     //    Unset region flag if needed.
  824.     //
  825.     if( $forceRegion )
  826.     {
  827.         setAttr ($globals[0] + ".urr") false;
  828.     }
  829. }
  830.  
  831. //
  832. //    This one can be used by hotkeys to check whether the image view is
  833. //    visible or not before calling redoLastImage procedure.
  834. //
  835. global proc checkAndRedoLastImage( int $forceRegion )
  836. {
  837.     if( `raiseImageViewWindow` == 1 )
  838.     {
  839.         redoLastImage( $forceRegion );
  840.         return;
  841.     }
  842.  
  843.     //
  844.     //    Then it may be nested in the main maya panel...
  845.     //
  846.     $imagePanel = `getImageWindowPanel`;
  847.  
  848.     for( $i in `getPanel -vis` )
  849.     {
  850.         if( $i == $imagePanel )
  851.         {
  852.             redoLastImage( $forceRegion );
  853.             return;
  854.         }
  855.     }
  856.  
  857.     //
  858.     //    Otherwise, make it appear...
  859.     //
  860.     scriptedPanel -e -tearOff $imagePanel;
  861.  
  862.     redoLastImage( $forceRegion );
  863. }
  864.  
  865. //----------------------------------------------------------------------------//
  866. //                        Low level helper procedures
  867. //----------------------------------------------------------------------------//
  868.  
  869. //
  870. // Description:
  871. //
  872. //
  873. global proc int[] getGlobalsResolution()
  874. {
  875.     //
  876.     //    Image globals item.
  877.     //
  878.     string    $globals[] = `ls -renderGlobals`;
  879.     int        $res[2] = { 320, 240 };
  880.  
  881.     if( size($globals[0]) > 0 )
  882.     {
  883.         string    $connect[] = `listConnections ($globals[0] + ".resolution")`;
  884.  
  885.         if( size($connect[0]) > 0 )
  886.         {
  887.             $res[0] = `getAttr ($connect[0] + ".width" )`;
  888.             $res[1] = `getAttr ($connect[0] + ".height" )`;
  889.         }
  890.     }
  891.  
  892.     return $res;
  893. }
  894.  
  895. //
  896. // Description:
  897. //
  898. //
  899. global proc int[] getTestResolution( string $panel )
  900. {
  901.     int        $res[2] = { 320, 240 };
  902.  
  903.     if( `optionVar -exists imageViewTestResolution` )
  904.     {
  905.         $testRes = `optionVar -query imageViewTestResolution`;
  906.  
  907.         if( $testRes == 0 )
  908.         {
  909.             if( size($panel) )
  910.             {
  911.                 string    $modelViewControl = `modelEditor -q -control $panel`;
  912.  
  913.                 if( size($modelViewControl) && `control -ex $modelViewControl` )
  914.                 {
  915.                     $res[0] = `control -q -w $modelViewControl`;
  916.                     $res[1] = `control -q -h $modelViewControl`;
  917.                 }
  918.             }
  919.         }
  920.         else
  921.         {
  922.             string    $globals[] = `ls -renderGlobals`;
  923.  
  924.             if( size($globals[0]) > 0 )
  925.             {
  926.                 string    $connect[] = `listConnections ($globals[0] + ".resolution")`;
  927.  
  928.                 if( size($connect[0]) > 0 )
  929.                 {
  930.                     $res[0] = `getAttr ($connect[0] + ".width" )`;
  931.                     $res[1] = `getAttr ($connect[0] + ".height" )`;
  932.  
  933.                     if( $testRes == 2 )
  934.                     {
  935.                         $res[0] /= 2;
  936.                         $res[1] /= 2;
  937.                     }
  938.                     else if( $testRes == 3 )
  939.                     {
  940.                         $res[0] /= 4;
  941.                         $res[1] /= 4;
  942.                     }
  943.                     else if( $testRes == 4 )
  944.                     {
  945.                         $res[0] /= 10;
  946.                         $res[1] /= 10;
  947.                     }
  948.                 }
  949.             }
  950.         }
  951.     }
  952.  
  953.     return $res;
  954. }
  955.  
  956. //
  957. // Description:
  958. //        Returns the image window editor, creates it if needed.
  959. //
  960. global proc string getImageWindowPanel()
  961. {
  962.     string $imagePanel;
  963.     string $imagePanels[] = `getPanel -scriptType "imageWindowPanel"`;
  964.  
  965.     if( size($imagePanels) == 0 )
  966.     {
  967.         $imagePanel = `scriptedPanel -type "imageWindowPanel" -unParent`;
  968.         scriptedPanel -e -lable `interToUI $imagePanel` $imagePanel;
  969.     }
  970.     else
  971.     {
  972.         $imagePanel = $imagePanels[0];
  973.     }
  974.  
  975.     return $imagePanel;
  976. }
  977.  
  978. //
  979. // Description:
  980. //
  981. //
  982. global proc string getImageWindowPanelFormLayout()
  983. {
  984.     string    $form, $sub, $child;
  985.     string    $panel = `getImageWindowPanel`;
  986.     int        $size = size($panel);
  987.  
  988.     for( $form in `lsUI -cl` )
  989.     {
  990.         $sub = substring($form,1,$size);
  991.  
  992.         if( $sub == $panel && `formLayout -exists $form` )
  993.         {
  994.             for( $child in `formLayout -q -ca $form` )
  995.             {
  996.                 if( $child == $panel )
  997.                     return $form;
  998.             }
  999.         }
  1000.     }
  1001.  
  1002.     return ($panel+"WindowPanelLayout_mainForm");
  1003. }
  1004.  
  1005. //
  1006. // Description:
  1007. //        Returns the current camera stored by the image window editor.
  1008. //    returns the current camera view if nothing stored in the image view or
  1009. //    the first camera.
  1010. //
  1011. global proc string getCurrentCamera()
  1012. {
  1013.     string    $null = "";
  1014.     return $null;
  1015. }
  1016.  
  1017. //
  1018. // Description:
  1019. //
  1020. //
  1021. global proc string getCameraPanel( string $camera )
  1022. {
  1023.     string    $null = "";
  1024.     return $null;
  1025. }
  1026.  
  1027. //
  1028. // Description:
  1029. //    Raise the image view window if exists, then return 1.
  1030. //    Return 0 otherwise.
  1031. //
  1032. global proc int raiseImageViewWindow()
  1033. {
  1034.     //
  1035.     //    Look for the imageViewWindow and pop it up if it exists.
  1036.     //
  1037.     for( $i in `lsUI -windows` )
  1038.     {
  1039.         if( $i == "imageViewWindow" )
  1040.         {
  1041.             showWindow $i;
  1042.             return 1;
  1043.         }
  1044.     }
  1045.  
  1046.     return 0;
  1047. }
  1048.